<?php
/**
 * 请求帮助类
 * User: 苏近之
 * Date: 2019-03-23
 * Time: 17:44
 */

namespace app\common\helper;

class Curl
{

    /**
     * GET 请求方法
     * @param String 请求路径
     * @return mixed
     */
    public static function sendGetRequest($url){
        $ch = curl_init();
        $isSSL = (substr($url,0,5) == 'https') ? true : false;
        if($isSSL){
            // 信任任何证书
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch, CURLOPT_PORT, 443);
            // 部分网站一定要启用下面这个选项
            curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
        }
        curl_setopt($ch,CURLOPT_TIMEOUT,1.2);
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch,CURLOPT_HEADER,0);
        $response = curl_exec($ch);
        if($response === false){
            return false;
        }
        curl_close($ch);

        return $response;
    }
}